// pages/watch02/index.js

Page({
    /**
     * 页面的初始数据
     */
    data: {
        name: ["xuyang", "lisi"],
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let that = this;
        Object.keys(this.watch).forEach((v) => {
            var val = this.data[v];
            console.log(val);

            Object.defineProperty(that.data, v, {
                set: function(value) {
                    val = value;
                    that.watch[v](val);
                },
                get: function() {
                    return val;
                },
            });
        });

        this.data.name[0] = "teressa"
        console.log(this.data.name);

    },

    watch: {
        name: function(newValue) {
            // name改变时, 调用该方法输出新值
            console.log(newValue);
        },
    },
});